package com.lbn.jfqsc.app.recruitment.detail;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lbn.baseframe.base.BaseActivity;
import com.lbn.baseframe.ui.NAppbar;
import com.lbn.baseframe.utils.DateUtils;
import com.lbn.jfqsc.App;
import com.lbn.jfqsc.R;
import com.lbn.jfqsc.app.login.LoginActivity;
import com.lbn.jfqsc.app.recruitment.apply.ApplyActivity;
import com.lbn.jfqsc.business.bean.JobList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class DetailActivity extends BaseActivity<DetailPresenter> implements IDetailView {
    @BindView(R.id.user_name)
    TextView userName;
    @BindView(R.id.time)
    TextView time;
    @BindView(R.id.phone)
    TextView phone;
    @BindView(R.id.address)
    TextView address;
    @BindView(R.id.content)
    TextView content;
    @BindView(R.id.collect)
    CheckBox collect;
    private JobList job;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail2);
        ButterKnife.bind(this);
        setAppbar(new NAppbar(this));
        appbar.setTitle("招聘详情");
        appbar.openBack();
        job = (JobList) getIntent().getSerializableExtra("job");
    }

    public static void startActivity(Context context, JobList job) {
        Intent intent = new Intent(context, DetailActivity.class);
        intent.putExtra("job", job);
        context.startActivity(intent);
    }

    @Override
    public void onPresenterCreated() {
        super.onPresenterCreated();
        userName.setText("发布人 : " + job.getUserName());
        time.setText("发布时间 : " + DateUtils.stampToDate(job.getCreateTime()));
        phone.setText("联系电话 : "+job.getUserPhone());
        address.setText("联系地址 : " + job.getPlace());
        content.setText(job.getContent());
        mPresenter.isCollection(job.getId());
    }

    @Override
    public DetailPresenter createPresenter() {
        return new DetailPresenter();
    }

//    @OnClick(R.id.apply)
//    public void onClick() {
//        ApplyActivity.startActivity(this);
//    }


    @Override
    public void setCollection(boolean b) {
        if(b){
            collect.setText("已收藏");
            collect.setEnabled(false);
            collect.setFocusable(false);
        }else{
            collect.setText("未收藏");
        }
        collect.setChecked(b);
    }

    @OnClick({R.id.collect, R.id.apply})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.collect:
                if(!App.isLogin()){
                    collect.setChecked(false);
                    LoginActivity.startActivity(this);
                    return;
                }
                mPresenter.collection(App.getUser().getId(),job.getId());
                break;
            case R.id.apply:
                ApplyActivity.startActivity(this);
                break;
        }
    }

}
